<?php
class Arm_Form_Element_ModelSelect extends Zend_Form_Element_Select{

    private $_model             = null;
    private $_condition         = array();
    private $_includeBlank      = true;
    
    public function setModel(Arm_Db_Table_Abstract $model){
        $this->_model = $model;
    }
       
    public function addCondition($condition){
        $this->_condition[] = $condition;
    }

    public function render(Zend_View_Interface $view  = null){
        $this->select();
        return parent::render($view);
    }

    private function select(){
        $model  = new $this->_model;
        $select = $model->getDefaultSelect();

        foreach($this->_condition as $condition){
            $select->where($condition);
        }
    
        if($this->_includeBlank){
            $this->addMultiOption(null, '- -');
        }
        foreach($model->fetchAll($select) as $item){
            $this->addMultiOption($item->key(), $item);
        }
    }
}
